package main

import (
	"com/hr/chapter03/mock"
	"com/hr/chapter03/real"
	"fmt"
	"time"
)

// 指针接收者实现只能以指针方式使用，值接收者都可以
type Regiever interface {
	Get(url string) string
}
type Poster interface {
	Post(url string, form map[string]string) string
}

func post(poster Poster) {
	poster.Post("http://www.baidu.com", map[string]string{
		"name": "huran",
	})
}

type RetrieverPoster interface {
	Regiever
	Poster
}

func session(r RetrieverPoster) {
	r.Get("")

}
func download(r Regiever) string {
	return r.Get("http://www.baidu.com")
}
func main() {
	var r Regiever
	// 指针接收者实现只能以指针方式使用，值接收者都可以
	r = mock.Regiever{Contents: "this is a huran.com"}
	r = &mock.Regiever{Contents: "this is a huran.com"}

	fmt.Printf("%T %v\n", r, r)
	a := r.(mock.Regiever)
	fmt.Println(a.Contents)

	r = &real.Retriever{UserAgent: "AAA", TimeOut: time.Minute}
	fmt.Printf("%T %v\n", r, r)
	b := r.(*real.Retriever)
	fmt.Println(b.UserAgent)

	// switch v := r.(type) {
	// case mock.Regiever:
	// 	fmt.Println(v.Contents)
	// case *real.Retriever:
	// 	fmt.Println(v.UserAgent)
	// }
	fmt.Println("===============")
}
